﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITM495.OOExamples.Core.Logger;

namespace ITM495.OOExamples.Core.Linq2Sql
{
    public class Linq2SqlController: IController
    {
        private ILogger logger = LogManager.GetLogger();

        #region IController Members

        public void Run(Options options)
        {
            logger.Log("In Linq2Sql controller.");

            var context = new AdventureWorkContextDataContext();
            var products = (from p in context.Products
                            where p.Color.StartsWith("B")
                            select new {p.Name, p.Color, Flag=  p.MakeFlag});

            foreach(var product in products)
            {
                logger.Log("Name: {0} ({1})", product.Name, product.Color);
            }

            logger.Log("Found {0} items.", products.Count());
        }

        #endregion
    }
}
